/**
 * 设置着色器,返回着色器程序对象
 * @param {WebGl对象} gl 
 */
function setupShader(gl){
    var vertexShader = gl.vertexShader;
    var fragmentShader = gl.fragmentShader;
    var program = gl.createProgram();
    if(!program){
        throw new Error("创建程序失败!");
        return null;
    }
    if(!vertexShader){
        throw new Error("顶点着色器为空!");
        return null;
    }
    if(!fragmentShader){
        throw new Error("片元着色器为空!");
        return null;
    }
    gl.attachShader(program, vertexShader);
    gl.attachShader(program, fragmentShader);
    gl.linkProgram(program);
    gl.useProgram(program);
    if(!gl.getProgramParameter(program, gl.LINK_STATUS)){
        throw new Error("设置着色器失败!");
        return null;
    }
    // 开启深度测试
    gl.enable(gl.DEPTH_TEST); 
    gl.program = program;
    return program;
}
export { setupShader };